#pragma once

#include "math/aabb.h"

struct triangle_t
{
	uint16 i1,i2,i3;
};
struct rendernode_t;
struct meshcollider_t
{
	void generate(rendernode_t*);
	void generate_aabb(uint32 aabb_index, uint32 first_tri,uint32 last_tri, int last_sort);

	bool intersect_sphere(float3& hit_pos, float3& hit_normal, const float4x4& parentmtx, const float3& center, float radius);
	void intersect_sphere_rec(uint32 aabb_index,uint32 first_tri,uint32 last_tri, float& tmin, float3& tripos,float3& trinormal, const float3& relcenter, float radius);


	vector<float3> pos;
	vector<triangle_t> tri;
	vector<aabb> bounding;
	float4x4 mtx;
};

void generate_meshcolliders(vector<rendernode_t>& nodebuf,vector<meshcollider_t>& colliders);